package cn.toma.core;

import java.util.HashMap;

/**
 * 响应结果生成工具
 */
public class ResultGenerator
{
	private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

	public static Result genSuccessResult()
	{
		return new Result()
				.setCode(ResultCode.SUCCESS)
				.setMessage(DEFAULT_SUCCESS_MESSAGE)
				.setData(new HashMap<>(2));

	}

	public static <T> Result<T> genSuccessResult(T data)
	{
		return new Result()
				.setCode(ResultCode.SUCCESS)
				.setMessage(DEFAULT_SUCCESS_MESSAGE)
				.setData(data);
	}

	public static Result genFailResult(String message)
	{
		return new Result()
				.setCode(ResultCode.FAIL)
				.setMessage(message)
				.setData(new HashMap<>(2));
	}

	public static Result genFailResult(ResultCode resultCode)
	{
		return new Result()
				.setCode(resultCode)
				.setMessage(resultCode.getMsg())
				.setData(new HashMap<>(2));
	}
}
